-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: parseReadme / better feature sections #373
Conversation
@magne4000 is it possible to access the flag of the current feature the processed |
The "current feature" is not necessarily defined by a flag, or could be behind multiple flag, so not possible. And currently we have no way to know if a file will be replaced by another later in the process. |
I really like it! |
It is less about the "current feature" more about the context a file is processed. |
I have thought about this, it's not really hard but my Markdown Viewer in VS Code provides this out of the box. |
Open Question:
|
I have an alternative proposal. Why not explicitly give the flag as a parameter to the loader or to the |
Replace the old one yes 👍
You can remove everything I think. Creating markdown tags manually is probably better anyway for IDEs that support embedded syntax highlighting. |
Thats what I would do if the value of flag is part of I would access the flag during export default async function getReadme(props: TransformerProps) {
const content = await loadMarkdown(props);
const flags = Array.from(props.meta.BATI)
.filter((f) => (f as string) !== "force")
.map((f) => `--${f}`)
.join(" ");
const v = getVersion();
//language=Markdown
const intro = `# Markdown`;
content.addMarkdown(intro);
return content.finalize(props);
} |
Why not make it even simpler for the main use case, which is adding markdown without any conditions, as simple as possible by having a specific naming e.g. |
Sorry I'm still not sure to understand. In this example, where is this file located? Then, let's assume that we have access to this flag under |
The code above is a export async function loadMarkdown({ readfile, meta }: TransformerProps) {
const content = await readfile?.();
return parseMarkdown(content ?? "", meta.flag);
} |
Okay, would there be a limitation to write it like this then? export async function loadMarkdown({ readfile, meta }: TransformerProps) {
const content = await readfile?.();
return parseMarkdown(content ?? "", "react");
} |
To simplify the discussion 😄 :
to test run This is still a draft and needs some cleanup but should be feature complete. The only known bugs are headers with special characters which are not correctly converted to internal links e.g.
|
My remarks about not being able to extract the current flag from the boilerplate name still stands. Its wrong to assume the boilerplate folder name is the flag, it's usually a coincidence for readability, but you cannot assume that this is or will always be the case. This means that addMarkdownFeature(markdown: string | ZoneHandler, flag: Flags) {
const category = features.find((f) => f.flag === flag)!.category as CategoryLabels;
this.contents.push({ markdown, options: { wrapper: { category, flag } } });
}
// usage becomes
content.addMarkdownFeature(todo, "aws"); |
I agree, that reengineering from the path is not the best way, but was a fast solution to show what I need. The right way would be to provide this information with the sources list, but this will be a bigger change in the build source code. To finish this, I will implement it as suggest by you and wait for the next use case to convince you that the name of the boilerplate value needed in transformed templates ;-) |
33abe18
to
d2e2c4e
Compare
@magne4000 removed localContext and implemented as suggested by you. Have a last check with this sample boilerplates: If there is nothing else to change, I would convert all existing README.md files to the new format. |
I have implemented a more robust approach to edit |
9c23f20
to
4f2234f
Compare
👏 Thank you very much! |
This will allow to build better structured documentation and README.md files - #364 .
The new features are:
packages/features/src/features.ts
Similar to the magicast loader for source files, the existing markdown files are converted to ast (mdast).
This allows the full range of manipulating markdown files or simple creation of markdown bei creating mdast nodes.
To make the transition to the new loader simple, the new loader is using a nearly identical interface - only the wrapper information needs to be added:
To compare the functionality of this draft with the existing loader the current commit contains copies of the existing READMEs:
boilerplates/shared/files/$TEST.md.ts
,boilerplates/sentry/files/$TEST.md.ts
,boilerplates/react/files/$TEST.md.ts
,boilerplates/aws/files/$TEST.md.ts
use this to test the new Markdown Manipulator to create a test project:
pnpm cli --sentry --hono --aws --react
Concept
All added or predefined section (e.g. intro, features) are wrapped in CommentMarks (e.g.
<!--bati:start section="features"--> ...content...<!--bati:end section="features"-->
. This allows to place and find any kind of unstructured markdown content.Based on the mdast tree and the zone callback which based on the filter set by calling
content.addMarkdown
the system will process all added blocks withcontent.finalize()
.Features supported by the current API:
{filter: {section:"features"}}
content.addMarkdown( (start, between, end, _info)=>{},wrapper: { category: "Frontend Framework", flag: "react"}
Example: